<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class M_nominate extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function get_nominations() {
        $this->db->select('GST.*,
            G.code AS group_code,
            S.name AS subject_name,
            T.name as teacher_name');
        $this->db->from('group_subject_teacher as GST');
        $this->db->join('groups as G', 'GST.id_group=G.id', 'left');
        $this->db->join('subjects as S', 'GST.id_subject=S.id', 'left');
        $this->db->join('teachers as T', 'GST.id_teacher=T.id', 'left');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function insert_nominate($id_group = '', $id_subject = '', $id_teacher = '') {

        $query = $this->db->query('SELECT * FROM group_subject_teacher WHERE id_group = "' . $id_group . '" AND id_subject = "' . $id_subject . '" AND id_teacher = "' . $id_teacher . '" ');

        if ($query->num_rows() > 0) {
            return lang('admin_nominate_required');
        } else {
            //$this->where('id_group', $id_group);
            //$this->get('students');
            $this->db->insert('group_subject_teacher', array('id_group' => $id_group, 'id_subject' => $id_subject, 'id_teacher' => $id_teacher));
            return lang('successfull');
        }
    }

    public function delete_nominations($nominations = array()) {

        foreach ($nominations as $id) {
            $this->db->delete('group_subject_teacher', array('id' => $id));
        }
    }

}

/* End of file m_teachers.php */
/* Location: ./application/models/m_teachers.php */